import { defineStore } from 'pinia'

export const useAuthStore = defineStore('auth', {
  state: () => ({
    token: localStorage.getItem('token') || '',
    profile: {},
    permissions: []
  }),

  actions: {
    setToken(token) {
      this.token = token
      localStorage.setItem('token', token)
    },

    setProfile(profile) {
      this.profile = profile
    },

    setPermissions(permissions) {
      this.permissions = permissions
    },

    clearAuth() {
      this.token = ''
      this.profile = {}
      this.permissions = []
      localStorage.removeItem('token')
    }
  }
})